package com.hailin.lease.web.app.service.Impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hailin.lease.model.entity.ViewAppointment;
import com.hailin.lease.web.app.mapper.ViewAppointmentMapper;
import com.hailin.lease.web.app.service.ApartmentInfoService;
import com.hailin.lease.web.app.service.ViewAppointmentService;
import com.hailin.lease.web.app.vo.apartment.ApartmentItemVo;
import com.hailin.lease.web.app.vo.appointment.AppointmentDetailVo;
import com.hailin.lease.web.app.vo.appointment.AppointmentItemVo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author: yuhailin
 * @description
 * @date: 2024/8/11 20:07
 */

@Service
public class ViewAppointmentServiceImpl extends ServiceImpl<ViewAppointmentMapper, ViewAppointment> implements ViewAppointmentService {
    @Autowired
    private ViewAppointmentMapper viewAppointmentMapper;
    @Autowired
    private ApartmentInfoService apartmentInfoService;
    /**
     * 根据用户id查询预约看房列表
     * @param userId
     * @return
     */
    public List<AppointmentItemVo> listItemByUserId(Long userId) {
        return viewAppointmentMapper.listItemByUserId(userId);
    }

    @Override
    public AppointmentDetailVo getDetailById(Long id) {
        ViewAppointment viewAppointment = viewAppointmentMapper.selectById(id);

        ApartmentItemVo apartmentItemVo = apartmentInfoService.selectApartmentItemVoById(viewAppointment.getApartmentId());

        AppointmentDetailVo agreementDetailVo = new AppointmentDetailVo();
        BeanUtils.copyProperties(viewAppointment, agreementDetailVo);

        agreementDetailVo.setApartmentItemVo(apartmentItemVo);

        return agreementDetailVo;
    }
}
